﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Collector.Certified
{
    public partial class CertifiedSettingForm : Form
    {
        public CertifiedSettingForm()
        {
            InitializeComponent();
            this.ControlBox = false;
            comboBox_TestMode.Items.Clear();
            for (int i = 0; i < FileConfig.testMode_Info.GetLength(0); i++)
            {
                string info = FileConfig.testMode_Info[i].mode;
                comboBox_TestMode.Items.Add(info);
            }

            checkBox_PulsePreTest.Checked = FileConfig.PulsePressureTest();
            checkBox_AirPreTest.Checked = FileConfig.AirPressureTest();
            checkBox_ThreeBody.Checked = FileConfig.PulseThreeBodyTest_Subsection();
            checkBox_Subsection.Checked = FileConfig.PulseSubsectionTest();
            comboBox_TestMode.SelectedIndex = FileConfig.CommonParam.iSelectedTestmode;

            reFlashUI();
        }

        private void reFlashUI()
        {
            int index = comboBox_TestMode.SelectedIndex;
            FileConfig.CommonParam.iSelectedTestmode = comboBox_TestMode.SelectedIndex;
            if (index < 0)
            {
                return;
            }
            //AppEvent.CallEvent(this, new AppEventArgs(EventId.UpdateInfo, 0, EventState.TestModeChange, index, null));
            AppEvent.CallEvent(this, new AppEventArgs(EventId.UpdateInfo, 0, EventState.UI, comboBox_TestMode.Text, index));

        }

        private void button_PlatformChange(object sender, EventArgs e)
        {
            reFlashUI();
        }

        private void Setting_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }

        private void button_OK_Click(object sender, EventArgs e)
        {
            FileConfig.testItem_Info.dictParams["PulsePressureTest"] = checkBox_PulsePreTest.Checked ? "1" : "0";
            FileConfig.testItem_Info.dictParams["AirPressureTest"] = checkBox_AirPreTest.Checked ? "1" : "0";
            FileConfig.testItem_Info.dictParams["PulseThreeBodyTest"] = checkBox_ThreeBody.Checked ? "1" : "0";
            FileConfig.testItem_Info.dictParams["PulseSubsectionTest"] = checkBox_Subsection.Checked ? "1" : "0";

            string ConfigFilePath = Application.StartupPath + "\\Setting.config";
            FileConfig.SaveCommonConfig(ConfigFilePath);
            int index = comboBox_TestMode.SelectedIndex;

            AppEvent.CallEvent(this, new AppEventArgs(EventId.UpdateInfo, 0, EventState.UI, comboBox_TestMode.Text, index));
            this.Close();
        }
    }
}
